Imports System.SerializableAttribute
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.IO
Imports System.Xml

<Serializable()> _
Public Class Index
    Inherits AttributeBase

    Private mlTableID As Long
    Private mlTableRevID As Long
    Private msName As String
    Private msIndex_Desc As String
    Private msKeys As String

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub New(ByVal lID As Long)
        MyBase.New(lID)
    End Sub

#Region "Properties"
    Public Property TableID() As Long
        Get
            Return mlTableID
        End Get
        Set(ByVal value As Long)
            mlTableID = value
        End Set
    End Property

    Public Property TableRevID() As Long
        Get
            Return mlTableRevID
        End Get
        Set(ByVal value As Long)
            mlTableRevID = value
        End Set
    End Property

    Public Property Name() As String
        Get
            Return msName
        End Get
        Set(ByVal value As String)
            msName = value
        End Set
    End Property

    Public Property Index_Desc() As String
        Get
            Return msIndex_Desc
        End Get
        Set(ByVal value As String)
            msIndex_Desc = value
        End Set
    End Property

    Public Property Keys() As String
        Get
            Return msKeys
        End Get
        Set(ByVal value As String)
            msKeys = value
        End Set
    End Property
#End Region

#Region "database"
    Public Sub Load()
        Dim oObject As New DBindex

        oObject.Load(Me)
    End Sub

    Public Sub Save()
        Dim oObject As New DBindex

        If mbObjectExists = True Then
            oObject.Update(Me)
        Else
            Me.CreateDate = Now
            oObject.Add(Me)
            mbObjectExists = True
        End If
    End Sub

    Public Sub Delete()
        Dim oObject As New DBindex

        oObject.Delete(Me)
        mbObjectExists = False
    End Sub
#End Region

    Public Function SerializeMe() As String
        Dim oMS As New MemoryStream
        Dim oSXML As New System.Xml.Serialization.XmlSerializer(GetType(SQLAutoDocLib.Index))
        oSXML.Serialize(oMS, Me)

        Dim oEncoding As System.Text.ASCIIEncoding = New System.Text.ASCIIEncoding
        Dim sXML As String = oEncoding.GetString(oMS.GetBuffer)

        Return sXML
    End Function
End Class
